	/*
	产品切换
*/


function Goods(){
	
}
Goods.prototype.getGoods = function(index,idx){
	ids  = cat_ids
	
	rand = Math.round(Math.random()*ids.length)

	
	cat_id = cat_id ? cat_id : ids
	
	switch(index)
	{
		case 0:
			type = 'best'
			break
		case 1:
			type = 'hot'
			break
		case 2:
			type = 'rand'
			break	
	}
	
	this.t_time = setTimeout("GS.getGoodsList(type,"+index+","+cat_id+","+idx+")",500)
}
Goods.prototype.clearTimeOut = function(){
	clearTimeout(this.t_time)
}
					
Goods.prototype.getGoodsList = function(type,index,cat_id,idx){
	this.tags = $(".ri_down .btq")
	this.div = $(".rid_border")
	this.tags.removeClass("hover")
	
	this.tags.eq(idx).addClass("hover")
	
	type = type ? type : 'best'
	
	data = "act=ajax_goods_list&type="+type+'&cat_id='+cat_id
	
	Ajax_loading.fadeIn()
	Main.AJAX("ajax.php", data, this.getGoodsListRes)
	
}
Goods.prototype.getGoodsListRes = function(res){
	var list = $(".list")
	res = eval("("+res+")")
	this.ajax_img = $(".ajax_img")
	Ajax_loading.fadeOut()
	for(i=0; i<res.length; i++)
	{
		goods_name = res[i].goods_name
		url  = res[i].url
		original_img = res[i].original_img 
		market_priced = res[i].market_priced
		shop_priced   = res[i].shop_priced
		list.eq(i).find("h3 a").html(goods_name)
		list.eq(i).find("h3 a").attr({"title":goods_name,"href":url})
		list.eq(i).find(".original_img").attr({"title":goods_name,"href":url})
		list.eq(i).find(".original_img  img").attr({"src":original_img,"alt":goods_name})
		list.eq(i).find(".rid_mprice").html(market_priced)
		list.eq(i).find(".rid_sprice").html(shop_priced)
		
	}
	
}

//更改属性价格
//change Attr
Goods.prototype.changeAttrPrices = function(goods_id,type){
	
	var attr_id = '';
	var num = '1';
	if(type=='goods')
	{
		attr_id = Cart.getAttr();
		
		attr_id = attr_id.join(",");	
	
		num = $(".qty").val();
	}
	
	if(num)
	{
		data = "act=change_attr_price&goods_number="+num+'&attr_id='+attr_id+'&goods_id='+goods_id;
		Main.AJAX("ajax.php",data,this.changeAttrPriceRes);
	}
}
Goods.prototype.changeAttrPriceRes = function(res){
	
	$(".total").html(res);
}
//取得商品价格
Goods.prototype.getPrice = function(){
		var data = 'act=get_price&g_id='+goods_id;
		Main.AJAX('ajax.php',data,this.getPriceRes);
}
	
Goods.prototype.getPriceRes = function(res){

		var res = eval("("+res+")")
		var s_price = res.shop_priced
		var m_price = res.market_priced
		$(".docu_sp").html(s_price)
		$(".docu_mp").html(m_price)
	}

Goods.prototype.setTimes = function(index){
   	
	this.t_time = setTimeout("desc.action("+index+")",500)
   
}

//编辑商品
Goods.prototype.goodsEdit = function(form){
   	var obj = $("."+form.className);
	var file = Main.getFiles(obj);
	var url = new Array;
	if(file)
	{
		for(var i in file)
		{
			url[url.length] = file[i].url;	
		}
		var joins = url.join("|||");
		obj.find("input[name=imgs]").val(joins);
	}
	form.submit();
	
   
}
//取得商品名称
Goods.prototype.getGoodsName = function(){
   var obj = $("input[name=goods_name]");
   var goods_name = obj.val();
   return goods_name;
 
}


var GS = new Goods()
